package com.basic.datapersist;

import org.apache.log4j.Logger;

import com.basic.common.FuncStatic;
 
public class DbFactory {
	private static Logger logger = Logger.getLogger ( DbFactory.class) ;
	
	/** @param clazz */
	public static <T> T  instance(DbConnectTool connect ,Class<? extends NeedConnect> clazz) {
		try {
			NeedConnect needConnect = clazz.newInstance();
			needConnect.initConnect(connect);
			return (T)needConnect;
		} catch (Exception e) {
			logger.error(FuncStatic.errorTrace(e));
		}
 		return null;
	}

	/**
	 * @param clazz
	 * @param key
	 */
	public static <T> T findObject(DbConnectTool connect , Class<? extends OneRowDataInit> clazz, Object key) {
		try {
			OneRowDataInit findByKey = clazz.newInstance();
			findByKey.initConnect(connect);
			findByKey.initByKey(key);
			return (T)findByKey;
		} catch (Exception e) {
			logger.error(FuncStatic.errorTrace(e));
		}
 		return null;
	}

	 
}